package com.example.manage_dzensaas.config;

import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

import javax.sql.DataSource;

/**
 * @author wangzhiqi
 * @version 1.0
 * @description: 配置类
 * @date 2025/2/12 12:17
 */
@Slf4j
@Configuration
public class Config {

    // 此下的 db1 与 mybatis.db1 将对应在起来 //可以用 @Db("db1") 注入mapper
    // typed=true，表示默认数据源。@Db 可不带名字注入
    @Bean(name = "db1", typed = true)
    public DataSource db1(@Inject("${datasource.db1}") HikariDataSource ds) {
        log.info("dataSource.db1.username={}", ds.getUsername());
        log.info("dataSource.db1.jdbcUrl={}", ds.getJdbcUrl());
        return ds;
    }

    @Bean(name = "db2")
    public DataSource db2(@Inject("${datasource.db2}") HikariDataSource ds) {
        log.info("dataSource.db2.username={}", ds.getUsername());
        log.info("dataSource.db2.jdbcUrl={}", ds.getJdbcUrl());
        return ds;
    }

}
